package com.jcl.recruit.apply.service;

import com.jcl.recruit.apply.mapper.InterviewMapper;
import com.jcl.recruit.apply.model.Interview;
import com.jcl.recruit.resume.logic.ResumeLogic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

/**
 * @author 刘明新
 * @date 2018/8/6 下午5:49
 */
@Service
public class InterviewService implements InterviewMapper {

    @Autowired
    private InterviewMapper interviewMapper;

    @Autowired
    private ResumeLogic     resumeLogic;

    @Override
    public Map<String,Object> selectPrimaryKeyById(Integer id) {
        return interviewMapper.selectPrimaryKeyById(id);
    }

    @Override
    public List<Map<String,Object>> selectAllInterviews(Integer status) {
        List<Map<String,Object>> interviewVos = interviewMapper.selectAllInterviews(status);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for(Map<String,Object> entity:interviewVos){
            if(entity.get("last_skd_times") != null) {
                entity.put("last_skd_times", sdf.format(entity.get("last_skd_time")));
            }
            if(entity.get("createtime") != null) {
                entity.put("createtime", sdf.format(entity.get("createtime")));
            }
        }
        return interviewVos;
    }

    public Map<String,Object> resuemDetail(Integer id){
        Map<String,Object> map = this.selectPrimaryKeyById(id);
        map.put("resume",resumeLogic.selectResumeByPrimsryKeyIdMap((Integer) map.get("resume_id")));
        return map;
    }

    @Override
    public int insertSelective(Interview record) {
        return interviewMapper.insertSelective(record);
    }

    @Override
    public int updateByPrimaryKeySelective(Interview record) {
        return interviewMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public Interview selectCountByResumeId(Integer resumeId) {
        return interviewMapper.selectCountByResumeId(resumeId);
    }

    @Override
    public List<Integer> selectCountByStatus() {
        return interviewMapper.selectCountByStatus();
    }
}
